<?php

class Model_MemberCenter extends Model {

    function __construct() {
        $this->Lookup = getModel('Model_Lookup');
        $this->Points = getModel('Model_Points');
        $this->Product_application = getModel('Model_ProductApplication');
        $this->Event_application = getModel('Model_EventApplication');
        $this->Member_application = getModel('Model_MemberApplication');
        $this->Product = getModel('Model_Product');
        $this->ProductReports = getModel('Model_ProductReports');
        $this->Member = getModel('Model_Member');
        $this->Limit_time = "2013-04-16 23:59:59";
    }

    function get_unfreeze_point($mid) {
        //product

        $param = $unfreeze_arr1 = array();
        $param['field'] = "TB1.id,TB1.mid,TB1.oid,TB2.name,TB2.cname,TB2.points";
        $param['where'] = "TB1.mid=" . $mid . " and TB1.application_status<7 and TB1.is_unfreeze_points=0 and TB1.status=1 and (UNIX_TIMESTAMP(TB2.apply_endtime)+4*24*3600)<UNIX_TIMESTAMP(now()) and TB1.addtime>='" . $this->Limit_time . "'";
        $param['order'] = "id desc"; //"id asc"
        $param['join'] = "LEFT JOIN product";
        $param['on'] = "TB1.oid = TB2.id";
        $unfreeze_arr1 = db_query_hash('product_application', $param);

        if (!empty($unfreeze_arr1['result'])) {
            foreach ($unfreeze_arr1['result'] as $value) {
                $_name = !empty($value['cname']) ? $value['cname'] : $value['name'];
                $ret = $this->Points->points_record($mid, "unfreeze_product_invite", str_replace("[產品名稱]", $_name, UNFREEZE_PRODUCT_INVITE_LANG), $value['oid'], $value['points']);
                if ($ret['ret'] != 0) {
                    db_update("product_application", array("is_unfreeze_points" => 1), "id=" . mysql_escape_string($value['id']) . " and mid=" . mysql_escape_string($value['mid']) . " and oid=" . mysql_escape_string($value['oid']));
                }
            }
        }

        //event
        $param1 = $unfreeze_arr2 = array();
        $param1['field'] = "TB1.id,TB1.mid,TB1.oid,TB2.title,TB2.points";
        $param1['where'] = "TB1.mid=" . $mid . " and TB1.application_status<7 and TB1.is_unfreeze_points=0 and TB1.status=1 and (UNIX_TIMESTAMP(TB2.endtime)+4*24*3600)<UNIX_TIMESTAMP(now()) and TB1.addtime>='" . $this->Limit_time . "'";
        $param1['order'] = "id desc"; //"id asc"
        $param1['join'] = "LEFT JOIN event";
        $param1['on'] = "TB1.oid = TB2.id";
        $unfreeze_arr2 = db_query_hash('event_application', $param1);

        if (!empty($unfreeze_arr2['result'])) {
            foreach ($unfreeze_arr2['result'] as $value) {
                $ret = $this->Points->points_record($mid, "unfreeze_event_invite", str_replace("[活動名稱]", $value['title'], UNFREEZE_EVENT_INVITE_LANG), $value['oid'], $value['points']);
                if ($ret['ret'] != 0) {
                    db_update("event_application", array("is_unfreeze_points" => 1), "id=" . mysql_escape_string($value['id']) . " and mid=" . mysql_escape_string($value['mid']) . " and oid=" . mysql_escape_string($value['oid']));
                }
            }
        }
        return 1;
        //echo '<pre>'.var_export($my_late_arr,1).'</pre>';
    }

    function get_expiration_point($mid) {
        //if($mid==1718) $this->Points->points_record($mid, "no_report", "測試測試".date ('Y-m-d H:i:s'));

        $param = $my_late_arr = array();
        $param['field'] = "TB1.id,TB1.mid,TB1.product,TB2.name,TB2.cname";
        $param['where'] = "TB1.mid=" . $mid . " and TB1.is_expiration=0 and TB1.is_submitted=0 and (UNIX_TIMESTAMP(TB1.report_endtime)+7*24*3600)<UNIX_TIMESTAMP(now()) and TB1.addtime>='" . $this->Limit_time . "'";
        $param['order'] = "id desc"; //"id asc"
        $param['join'] = "LEFT JOIN product";
        $param['on'] = "TB1.product = TB2.id";
        $my_late_arr = db_query_hash('member_application', $param);


        if (!empty($my_late_arr['result'])) {
            foreach ($my_late_arr['result'] as $value) {
                $_name = !empty($value['cname']) ? $value['cname'] : $value['name'];
                $ret = $this->Points->points_record($mid, "no_report", str_replace("[產品名稱]", $_name, NO_REPORT_LANG));

                if ($ret['ret'] != 0) {
                    db_update("member_application", array("is_expiration" => 1), "id=" . mysql_escape_string($value['id']) . " and mid=" . mysql_escape_string($value['mid']) . " and product=" . mysql_escape_string($value['product']));
                }
            }
        }
        return 1;
        //echo '<pre>'.var_export($my_late_arr,1).'</pre>';
    }

    function get_p_bt($i, $v, $s = 0) {
        $status_type = array();
        $status_type[0][0] = 1; //已申請，未獲邀
        $status_type[0][1] = 2; //已成功獲請，已過期，不可以接受
        $status_type[1][1] = 3; //已成功獲請，可以接受
        $status_type[0][3] = 4; //已成功獲請，已拒絕
        $status_type[0][2] = 5; //已獲邀，已接受，未提交報告，已過期不可以提交報告
        $status_type[0][4] = 6; //已獲邀，已接受，已提交報告
        $status_type[2][2] = 7; //已獲邀，已接受，未提交報告，可以提交報告


        $status_arr = array(
            0 => '已申請',
            1 => '成功<br/>獲邀',
            2 => '已接受<br/>邀請',
            3 => '已拒絕<br/>邀請',
            4 => '已提交<br/>報告',
        );
        $ret_arr = array(
            0 => array(
                '_pstatus' => $status_arr[$s],
                '_css' => 'btn btn_view',
                '_bt' => '查看',
                'show_endtime' => 0,
                '_bturl' => optimize_url('product', 'invite_inpage', 'mtype=' . $v['member_type'] . '&pid=' . $v['id']),
                'status_type' => $status_type[$i][$s]
            ),
            1 => array(
                '_pstatus' => $status_arr[$s],
                '_css' => 'btn btn_accept',
                '_bt' => '接受',
                'show_endtime' => 1,
                '_bturl' => optimize_url('product', 'report_show', 'mtype=' . $v['member_type'] . '&pid=' . $v['id'] . '&aid=' . $v['application_id']),
                'status_type' => $status_type[$i][$s]
            ),
            2 => array(
                '_pstatus' => $status_arr[$s],
                '_css' => 'btn btn_s_report',
                '_bt' => '提交报告',
                'show_endtime' => 0,
                '_bturl' => '/member_center.php?action=report',
                'status_type' => $status_type[$i][$s]
            ),
        );
        return $ret_arr[$i];
    }

    function get_e_bt($i, $v, $s = 0, $t = 0) {
        $status_arr = array(
            0 => '已申請',
            1 => '成功<br/>獲邀',
            2 => '已接受<br/>邀請',
            3 => '已拒絕<br/>邀請'
        );
        $txt_arr = array(
            0 => '審核中',
            1 => '未確認',
            2 => '已確認',
            3 => '已拒絕'
        );
        $ret_arr = array(
            0 => array(
                '_pstatus' => $status_arr[$s],
                '_css' => 'btn btn_view',
                '_bt' => $txt_arr[$t],
                'show_endtime' => 0,
                '_bturl' => optimize_url('events', 'invite_inpage', 'eid=' . $v['id'])
            ),
            1 => array(
                '_pstatus' => $status_arr[$s],
                '_css' => 'btn btn_accept',
                '_bt' => $txt_arr[$t],
                'show_endtime' => 1,
                '_bturl' => optimize_url('events', 'show', 'eid=' . $v['id'] . '&aid=' . $v['application_id'])
            ),
            2 => array(
                '_pstatus' => $status_arr[$s],
                '_css' => 'btn btn_view',
                '_bt' => $txt_arr[$t],
                'show_endtime' => 0,
                '_bturl' => optimize_url('events', 'invite_result', 'eid=' . $v['id'])
            )
        );
        return $ret_arr[$i];
    }

    function productResult($memberid, $type) {
        $data = $this->Product_application->getMyApplicationList($memberid, $type, "TB1.id desc", 1, 200);
        if (!empty($data['result'])) {
            foreach ($data['result'] as $k => $v) {
                $data['result'][$k]['_photo_url'] = PhotoResize($v['cover'], 158, 158);
                $data['result'][$k]['_difTime'] = explode(" ", str_diff_time($v['apply_endtime']));
                $data['result'][$k]['body'] = wordscut($v['body'], 50);
                $_temp = array();
                if ($v['application_status'] == 7) {
                    if (time() >= strtotime($v['apply_starttime']) && time() <= strtotime($v['accept_endtime'])) {
                        $_temp = $this->get_p_bt(1, $v, 1);
                    } else {
                        $_temp = $this->get_p_bt(0, $v, 1);
                    }
                } elseif ($v['application_status'] == 9) {
                    $_issubmit = db_query_count('member_application', 'is_submitted=1 and status=1 and mid=' . mysql_escape_string($memberid) . ' and product=' . mysql_escape_string($v['id']));
                    if (time() >= strtotime($v['report_starttime']) && time() <= (strtotime($v['report_endtime']) + 7 * 24 * 3600)) {
                        $_temp = ($_issubmit > 0) ? $this->get_p_bt(0, $v, 4) : $this->get_p_bt(2, $v, 2);
                    } else {
                        $_temp = ($_issubmit > 0) ? $this->get_p_bt(0, $v, 4) : $this->get_p_bt(0, $v, 2);
                    }
                } elseif ($v['application_status'] == 11) {
                    $_temp = $this->get_p_bt(0, $v, 3);
                } elseif ($v['application_status'] <= 5) {
                    $_temp = $this->get_p_bt(0, $v, 0);
                }
                $data['result'][$k] = array_merge($data['result'][$k], $_temp);
            }
        }

        return $data;
    }

    function eventResult($memberid, $type) {
        $data = $this->Event_application->getMyApplicationList($memberid, $type, "TB1.id desc", 1, 200);
        $data1 = $this->Lookup->getLookup('event');
        $event_type = array();
        if (!empty($data1['result'])) {
            foreach ($data1['result'] as $v) {
                $event_type[$v['id']] = $v['cname'];
            }
        }
        if (!empty($data['result'])) {
            foreach ($data['result'] as $k => $v) {
                $data['result'][$k]['type_name'] = $event_type[$v['event_type']];
                $data['result'][$k]['_photo_url'] = PhotoResize($v['cover'], 158, 158);
                $data['result'][$k]['_difTime'] = explode(" ", str_diff_time($v['endtime']));
                $data['result'][$k]['intro'] = wordscut($v['intro'], 50);

                $_temp = array();
                if (time() >= strtotime($v['starttime']) && time() <= strtotime($v['accept_endtime'])) {
                    if ($v['application_status'] == 7) {
                        $_temp = $this->get_e_bt(1, $v, 1, 1);
                    } elseif ($v['application_status'] == 9) {
                        $_temp = $this->get_e_bt(0, $v, 2, 2);
                    } elseif ($v['application_status'] == 11) {
                        $_temp = $this->get_e_bt(0, $v, 3, 3);
                    } elseif ($v['application_status'] <= 5) {
                        $_temp = $this->get_e_bt(0, $v, 0, 0);
                    }
                } else {
                    if ($v['application_status'] == 7) {
                        $_temp = $this->get_e_bt(2, $v, 1, 1);
                    } elseif ($v['application_status'] == 9) {
                        $_temp = $this->get_e_bt(2, $v, 2, 2);
                    } elseif ($v['application_status'] == 11) {
                        $_temp = $this->get_e_bt(2, $v, 3, 3);
                    } elseif ($v['application_status'] <= 5) {
                        $_temp = $this->get_e_bt(2, $v, 0, 0);
                    }
                }
                $data['result'][$k] = array_merge($data['result'][$k], $_temp);
            }
        }

        return $data;
    }

    function get_invite_type($t) {
        //說明： $c 1產品 2活動 | $type 0全部 2 成功邀請 1 審核中、拒絕
        //array(0=>"全部",1=>'成功獲邀產品',2=>'已申請的產品',3=>'已接受邀請產品',4=>'成功獲邀活動',5=>'已參加的活動',6=>'已接受邀請活動');
        $_invite_arr = array(
            0 => array('type' => 0, 'c' => 0),
            1 => array('type' => 2, 'c' => 1),
            2 => array('type' => 0, 'c' => 1),
            3 => array('type' => 3, 'c' => 1),
            4 => array('type' => 2, 'c' => 2),
            5 => array('type' => 0, 'c' => 2),
            6 => array('type' => 3, 'c' => 2)
        );
        return $_invite_arr[$t];
    }

    function h_get_report_type($h_param = array()) {
        $prama = array();
        $prama_key_0 = array('mid', 'type');
        if ($prama_key_0) {
            foreach ($prama_key_0 as $value) {
                $prama[$value] = (!empty($h_param[$value])) ? $h_param[$value] : 0;
            }
        }
        if (!$prama['mid'])
            return array();


        $prama['page'] = intval($h_param['page']) ? intval($h_param['page']) : 1;
        $prama['size'] = intval($h_param['size']) ? intval($h_param['size']) : 4;

        return $this->get_report_type($prama['mid'], $prama['type'], $prama['page'], $prama['size']);
    }

    function get_report_type($mid, $t, $page, $pagesize) {
        $myApplicationList = $this->Member_application->getMyApplicationList($mid, $t, "TB1.addtime desc", $page, $pagesize);
        if (!empty($myApplicationList['result'])) {
            foreach ($myApplicationList['result'] as $k => $v) {
                $myApplicationList['result'][$k]['name'] = wordscut($v['name'], 10);
                $myApplicationList['result'][$k]['cname'] = wordscut($v['cname'], 10);
                $myApplicationList['result'][$k]['_photo_url'] = PhotoResize($v['cover'], 116, 116);
                $myApplicationList1 = $this->Product->getProductById($v['id']);
                $myApplicationList['result'][$k]['_rep_count'] = empty($myApplicationList1['reports']) ? 0 : $myApplicationList1['reports'];
                $myApplicationList['result'][$k]['my_report_starttime'] = strtotime($v['my_report_starttime']) < strtotime("2000-01-01") ? $v['report_starttime'] : $v['my_report_starttime'];
                if ($v['is_submitted'] == 0) {
                    $myApplicationList = $this->get_report_issubmit($myApplicationList, $k, $myApplicationList['result'][$k], $mid);
                } else {
                    $myApplicationList = $this->get_report_notsubmit($myApplicationList, $k, $myApplicationList['result'][$k], $mid);
                }
            }
        }
        return $myApplicationList;
    }

    function get_reject_report($mid, $page, $pagesize) {
        $myApplicationList = $this->Member_application->getMyApplicationList($mid, 3, "TB1.addtime desc", $page, $pagesize);
        if (!empty($myApplicationList['result'])) {
            foreach ($myApplicationList['result'] as $k => $v) {
                $myApplicationList['result'][$k]['name'] = wordscut($v['name'], 12);
                $myApplicationList['result'][$k]['cname'] = wordscut($v['cname'], 12);
                $myApplicationList['result'][$k]['_photo_url'] = PhotoResize($v['cover'], 116, 116);
                $myApplicationList1 = $this->Product->getProductById($v['id']);
                $myApplicationList['result'][$k]['_rep_count'] = empty($myApplicationList1['reports']) ? 0 : $myApplicationList1['reports'];
                $myApplicationList['result'][$k]['_bt'] = '編輯';
                $myApplicationList['result'][$k]['_bt_s'] = 6;
                $myApplicationList['result'][$k]['_css'] = 'btn_s btn_s_edit';
                $myApplicationList['result'][$k]['_bturl'] = optimize_url('product', 'report_edit', 'mtype=' . $v['member_type'] . '&pid=' . $v['product'] . '&rid=' . $v['rid']);
            }
        }
        return $myApplicationList;
    }

    function get_report_issubmit(&$myApplicationList, $k, $v, $mid) {
        $draft = db_query_one('product_reports', array('field' => 'id', 'where' => 'oid=' . $v['product'] . ' and mid=' . $mid . ' and is_publish=0 and is_accept=0 and status=1'));
        if (!empty($draft['result'])) {
            $myApplicationList['result'][$k]['_bt'] = '草稿';
            $myApplicationList['result'][$k]['_bt_s'] = 6;
            $myApplicationList['result'][$k]['_css'] = 'btn_s btn_s_draft_e';
            $myApplicationList['result'][$k]['_bturl'] = optimize_url('product', 'report_edit', 'mtype=' . $v['member_type'] . '&pid=' . $v['product'] . '&rid=' . $draft['result']['id']);
            $myApplicationList['result'][$k]['rid'] = $draft['result']['id'];
        } else {
            $myApplicationList['result'][$k]['_bt_s'] = 0;

            if (time() < strtotime($v['my_report_starttime'])) {
                $myApplicationList['result'][$k]['_bt_s'] = 1;
                $myApplicationList['result'][$k]['_bt'] = '未開始提交';
                $myApplicationList['result'][$k]['_bturl'] = 'javascript:void(0);';
                $myApplicationList['result'][$k]['_css'] = 'btn_no btn_s_submit ';
            }
            if ((time() >= strtotime($v['my_report_starttime']) && time() <= strtotime($v['my_report_endtime'])) || !empty($v['is_member_delay'])) {
                $myApplicationList['result'][$k]['_bt'] = '開始提交';
                $myApplicationList['result'][$k]['_bt_s'] = 2;
                $myApplicationList['result'][$k]['_bturl'] = optimize_url('product', 'report_add', 'pid=' . $v['product']);
                $myApplicationList['result'][$k]['_css'] = 'btn_s btn_s_submit';
            }

            $last_time = strtotime($v['my_report_endtime']) + 3600 * 24 * 7;

            if (time() > strtotime($v['my_report_endtime']) && time() <= $last_time) {
                if (empty($v['is_member_delay'])) {
                    //$email_obj->send($this->member['id'], "app_overdue_success", array("cname" => $myApplicationList['result'][$k]['cname']));
                    db_update('member_application', array('is_member_delay' => 1), 'product=' . mysql_escape_string($v['product']) . ' and mid=' . mysql_escape_string($mid));
                }
                $myApplicationList['result'][$k]['_bt_s'] = 3;
                $myApplicationList['result'][$k]['_bt'] = '延期';
                $myApplicationList['result'][$k]['_bturl'] = 'javascript:void(0);';
                $myApplicationList['result'][$k]['_css'] = 'btn_s btn_s_submit ';
            }

            if (time() > $last_time) {
                $myApplicationList['result'][$k]['_bt_s'] = 4;
                $myApplicationList['result'][$k]['_bt'] = '逾期提交';
                $myApplicationList['result'][$k]['_bturl'] = 'javascript:void(0);';
                $myApplicationList['result'][$k]['_css'] = 'btn_s delay';
            }
        }
        return $myApplicationList;
    }

    function get_report_notsubmit(&$myApplicationList, $k, $v, $mid) {
        $_res = db_query_one('product_reports', array('field' => 'id,is_accept', 'where' => 'id=' . $v['rid'] . ' and oid=' . $v['product'] . ' and mid=' . $mid . ' and status=1'));
        if (!empty($_res['result'])) {
            if ($_res['result']['is_accept'] == 1) {
                $myApplicationList['result'][$k]['_bt'] = '已刊登';
                $myApplicationList['result'][$k]['_bt_s'] = 5;
                $myApplicationList['result'][$k]['_css'] = 'btn_s seereport';
                $myApplicationList['result'][$k]['_bturl'] = optimize_url('product', 'detail', 'mtype=' . $v['member_type'] . '&pid=' . $v['product']);
                $myApplicationList['pageinfo']['total'] = intval($myApplicationList['pageinfo']['total']) - 1;
            } else {
                $myApplicationList['result'][$k]['_bt'] = '編輯';
                $myApplicationList['result'][$k]['_bt_s'] = 6;
                $myApplicationList['result'][$k]['_css'] = 'btn_s btn_s_edit';
                $myApplicationList['result'][$k]['_bturl'] = optimize_url('product', 'report_edit', 'mtype=' . $v['member_type'] . '&pid=' . $v['product'] . '&rid=' . $v['rid']);
            }
        }
        return $myApplicationList;
    }

    function get_member($member) {
        $_mem1 = $this->Member->getMember($member['id']);
        $_mem2 = $this->Member->getMemberCondition($member['id']);
        $member['age_group'] = $_mem1['result'][0]['age'];
        $_body_skin = empty($_mem2['result'][0]['body_skin']) ? $this->Lookup->getLookup('body_skin', 1) : $this->Lookup->getLookup('body_skin', $_mem2['result'][0]['body_skin']);
        $member['body_skin'] = $_body_skin['result'][0]['cname'];
        //$member['points'] = intval($_mem1['result'][0]['points']) + intval($_mem1['result'][0]['points_freeze']);
        $member['points'] = intval($_mem1['result'][0]['points']);
        $member['points_freeze'] = $_mem1['result'][0]['points_freeze'];
        $member['share_url'] = DOMAIN . "member.php?action=reg&friend=" . $member['username'];
        if (!empty($_mem2['result'][0]['brand'])) {
            $array = explode(",", $_mem2['result'][0]['brand']);
            if ($array) {
                foreach ($array as $key => $value) {
                    if (!$value) {
                        unset($array[$key]);
                    }
                }
            }
            $_brand = db_query_hash('brand', array('field' => 'name', 'where' => 'id in (' . implode(",", $array) . ')'));
            $_brand_temp = $_brand_t_arr = array();
            $_brand_t_len = 30;
            $_brand_t_l = 0;
            if (!empty($_brand['result'])) {
                foreach ($_brand['result'] as $v) {
                    $_brand_list[] = $v['name'];
                    $_len_temp = strlen($v['name']);
                    if (($_brand_t_l + $_len_temp) <= $_brand_t_len) {
                        $_brand_t_arr[] = $v['name'];
                        $_brand_t_l += $_len_temp;
                    } else {
                        $_brand_temp[] = $v['name'];
                    }
                }
            }
            $member['fav_brand'] = implode(' , ', $_brand_temp);
            $member['fav_brand_top'] = implode(' , ', $_brand_t_arr);
        } else {
            $member['fav_brand'] = $member['fav_brand_top'] = '';
        }

        $member['member_type'] = $_mem1['result'][0]['member_type'];
        $member['photo_l'] = imore_avatar($member['photo']);

        $member['reports_count'] = db_query_count('product_reports', ' mid=' . mysql_escape_string($member['id']) . ' and is_blog=0 and  status=1');


        if (!empty($_mem2['result'][0]['address']) && !empty($_mem2['result'][0]['homepage']) && intval($member['member_type']) != 5) {//是否會員審核中
            $member['_status'] = 1;
        } else {
            $member['_status'] = 0;
        }
        return $member;
    }

    function get_my_reports($my_reports_res) {
        $my_reports = $_temp = array();
        if (!empty($my_reports_res['result'])) {
            foreach ($my_reports_res['result'] as $k => $v) {
                $product_info = $this->Product->getProductById($v['oid']);
                if (!empty($product_info)) {
                    $my_reports[$k]['product']['id'] = $v['oid'];
                    $my_reports[$k]['product']['name'] = $product_info['name'];
                    $my_reports[$k]['product']['cname'] = $product_info['cname'];
                    $my_reports[$k]['product']['type_name'] = $product_info['type_name'];
                    $my_reports[$k]['product']['photo'] = PhotoResize($product_info['cover'], 116, 116);
                    $my_reports[$k]['product']['member_type'] = $product_info['member_type'];
                    $my_reports[$k]['product']['good'] = $product_info['product_reports_stat']['good'];
                    $my_reports[$k]['product']['common'] = $product_info['product_reports_stat']['common'];
                    $my_reports[$k]['product']['bad'] = $product_info['product_reports_stat']['bad'];

                    $my_reports[$k]['report']['id'] = $v['id'];
                    $my_reports[$k]['report']['title'] = $v['title'];
                    $my_reports[$k]['report']['body'] = wordscut($v['body'], 100);
                    $my_reports[$k]['report']['likes'] = $v['likes'];
                    $my_reports[$k]['report']['well'] = $v['well'];
                    //$my_reports[$k]['report']['time'] = ($v['lastmodify'] && strtotime($v['lastmodify']) >0)?$v['lastmodify']:$v['addtime'];
                    $my_reports[$k]['report']['time'] = $v['addtime'];

                    if (!empty($product_info['vote_option_data']['result'])) {
                        foreach ($product_info['vote_option_data']['result'] as $k1 => $v1) {
                            $my_reports[$k]['report']['category'][$k1]['k'] = $k1;
                            $my_reports[$k]['report']['category'][$k1]['name'] = $v1['cname'];
                            $my_reports[$k]['report']['category'][$k1]['value'] = @$v['category_score' . ($k1 + 1)];
                        }
                    }


                    $_temp = json_decode($v['content_json'], true);
                    $ii = 1;
                    if (!empty($_temp)) {
                        foreach ($_temp as $k2 => $v2) {
                            $my_reports[$k]['report']['content'][$ii]['p'] = PhotoResize($v2['p'], 163, 102);
                            $my_reports[$k]['report']['content'][$ii]['t'] = $v2['t'];
                            $ii++;
                        }
                    }
                }
            }
        }
        return $my_reports;
    }

    function get_my_like_reports($my_like_reports_res) {
        $my_like_reports = $_temp = array();
        if (!empty($my_like_reports_res)) {
            foreach ($my_like_reports_res as $k => $v) {
                $_product_report = $this->ProductReports->getReportsList(0, 0, $v['sid']);
                if (!empty($_product_report['result'][0])) {
                    $_product_info = $this->Product->getProductById($_product_report['result'][0]['oid']);
                    if (!empty($_product_info)) {
                        $my_like_reports[$k]['product']['id'] = $_product_report['result'][0]['oid'];
                        $my_like_reports[$k]['product']['name'] = $_product_info['name'];
                        $my_like_reports[$k]['product']['cname'] = $_product_info['cname'];
                        $my_like_reports[$k]['product']['type_name'] = $_product_info['type_name'];
                        $my_like_reports[$k]['product']['photo'] = PhotoResize($_product_info['cover'], 116, 116);
                        $my_like_reports[$k]['product']['good'] = $_product_info['product_reports_stat']['good'];
                        $my_like_reports[$k]['product']['common'] = $_product_info['product_reports_stat']['common'];
                        $my_like_reports[$k]['product']['bad'] = $_product_info['product_reports_stat']['bad'];
                        $my_like_reports[$k]['product']['member_type'] = $_product_info['member_type'];

                        $my_like_reports[$k]['report']['id'] = $_product_report['result'][0]['id'];
                        $my_like_reports[$k]['report']['title'] = $_product_report['result'][0]['title'];
                        $my_like_reports[$k]['report']['body'] = wordscut($_product_report['result'][0]['body'], 100);
                        $my_like_reports[$k]['report']['likes'] = $_product_report['result'][0]['likes'];
                        $my_like_reports[$k]['report']['well'] = $_product_report['result'][0]['well'];
                        //$my_like_reports[$k]['report']['time'] = ($_product_report['result'][0]['lastmodify'] && strtotime($_product_report['result'][0]['lastmodify']) >0)?$_product_report['result'][0]['lastmodify']:$_product_report['result'][0]['addtime'];
                        $my_like_reports[$k]['report']['time'] = $_product_report['result'][0]['addtime'];
                        if (!empty($_product_info['vote_option_data']['result'])) {
                            foreach ($_product_info['vote_option_data']['result'] as $k1 => $v1) {
                                $my_like_reports[$k]['report']['category'][$k1]['k'] = $k1;
                                $my_like_reports[$k]['report']['category'][$k1]['name'] = $v1['cname'];
                                $my_like_reports[$k]['report']['category'][$k1]['value'] = $_product_report['result'][0]['category_score' . ($k1 + 1)];
                            }
                        }

                        $_temp = json_decode($_product_report['result'][0]['content_json'], true);
                        $ii = 1;
                        if (!empty($_temp)) {
                            foreach ($_temp as $k2 => $v2) {
                                $my_like_reports[$k]['report']['content'][$ii]['p'] = PhotoResize($v2['p'], 163, 102);
                                $my_like_reports[$k]['report']['content'][$ii]['t'] = $v2['t'];
                                $ii++;
                            }
                        }
                    }
                }
            }
        }
        return $my_like_reports;
    }

    function get_member_status($member) {
        $_mem = $this->Member->getMemberCondition($member['id']);
        $_member_arr = array();
        if ($_mem['result'])
            $_member_arr = $_mem['result'][0];
        $_isexp = 0;
        if ((!empty($_member_arr['address']) && !empty($_member_arr['homepage'])) || $member['member_type'] == 5) {
            $_isexp = 1;
        }
        return $_isexp;
    }

}

?>